<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>天翼云-OOS-上传</title>
</head>
<script src="oos-sdk-6.0.min.js"></script>
<body>
<input type="file" id="file">
<input type="button" value="上传" onclick="put_object();">
</body>

<script>

//初始化
window.onload = function(){
    endPoint = "oos-hazz.ctyunapi.cn";
	accessKeyId = "8689a927cab4e0b9e4d8";
	secretAccessKey = "d85b366875487cec252a881c491a5bcd8f4a832a";
	bucket = "jyzx";
	var s3Config = {
		accessKeyId: accessKeyId,
		secretAccessKey: secretAccessKey,
		endpoint: endPoint,
		signatureVersion: 'v4', // 可选v2 或v4
		apiVersion: '2006-03-01',
		s3ForcePathStyle: true,
		bucket:bucket
	};

	client = new OOS.S3(s3Config);
}

//上传
function put_object() {
    var file = document.getElementById('file').files[0];
    var key = 'weigh/'+file.name;
	var params = {
		Body: file,
		Bucket: bucket,
		Key: key
	};
	client.putObject(params, function (err, data) {
		if (err){
		    console.log(err, err.stack);
		}else{
			console.log(data);
		}
	});
}
</script>
</body>
</html>